package test_junit_shop.ManageConstruction;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.util.Random;

/**
 * Created by ZH on 2018/2/5.
 * 门店-施工项目新增/删除
 */
public class AddConstructionProject {
    private static AddConstructionProject acp = new AddConstructionProject();
    private WebDriver driver;
    public static AddConstructionProject getInstance(){
        return acp;
    }
    public void setwDriver(WebDriver w){
        driver = w;
    }
    public WebDriver getwDriver(){
        return driver;
    }

    String flag = "0";

    public void addConstructionClass() throws InterruptedException {
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/div/div/button")).click();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"layui-layer-iframe1\"]")));
        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@id=\"detail-form\"]/div[2]/div/div/label")).click();
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.findElement(By.xpath("//*[@id=\"layui-layer1\"]/div[3]/a[1]")).click();
        Thread.sleep(2000);

    }

    public void addConstructionProject() throws InterruptedException {
        Random r = new Random();
        int i = 3;
        while (i-- > 0){
            flag += r.nextInt(10);
        }

        driver.findElement(By.xpath("//*[@id=\"category\"]/li[2]/div/span")).click();
        Thread.sleep(3000);
        driver.findElement(By.xpath("//*[@id=\"operation\"]/p/button[1]")).click();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"layui-layer-iframe1\"]")));
        Thread.sleep(2000);
        driver.findElement(By.id("name")).sendKeys("测试"+flag);
        driver.findElement(By.id("estimationHour")).sendKeys("12");
        driver.findElement(By.xpath("//*[@id=\"custom\"]/div/div/input")).sendKeys("800");
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.findElement(By.xpath("//*[@id=\"layui-layer1\"]/div[3]/a[1]")).click();
    }

    public void deleteConstructionProject() throws InterruptedException {
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        Thread.sleep(2000);
        driver.findElement(By.name("btSelectItem")).click();
        Thread.sleep(1000);
        driver.findElement(By.xpath("//*[@id=\"operation\"]/p/button[4]")).click();
        Thread.sleep(1000);
        driver.findElement(By.xpath("/html/body/div[4]/div[3]/a[1]")).click();
    }

}
